﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using WPLDB.DA.Interfaces;
using WPLDB.Utility.Extensions;
using WPLDB.Infrastucture;

namespace WPLDB.Code
{
    /// <summary>
    ///  This class helps to insert Namespace information to designer class 
    ///  and variables naming are not explicit required the explanations
    /// </summary>
    public class CreateNameSpaceCode : ICreateClassCode
    {

        #region "Variables"
        private string _nameSpace = "";
        private string _content = "";

        #endregion

        #region "ctor"

        public CreateNameSpaceCode(string nameSpace, string content)
        {
            _nameSpace = nameSpace;
            _content = content;
        }

        #endregion

        #region "Constants"

        string NAMESPACE = "[COMMENT1][NEWLINE][NEWLINE][PROPERTYTYPE][NEWLINE][NEWLINE]namespace [CLASSNAME][NEWLINE]{[NEWLINE][CONSTRUCTORCONTENT][NEWLINE]}[NEWLINE]";

        string IMPORTS = "using [PROPERTY];[NEWLINE]";
        string COMMENT1 = "//------------------------------------------------------------------------------[NEWLINE]" +
                            "// <auto-enerated>[NEWLINE]" +
                            "//    This code was generated from a template.[NEWLINE]" +
                            "//[NEWLINE]" +
                            "//    Manual changes to this file may cause unexpected behavior in your application.[NEWLINE]" +
                            "// </auto-generated>[NEWLINE]" +
                            "//------------------------------------------------------------------------------[NEWLINE]";



        #endregion

        #region "Interface Implementation"

        public string GenerateClassString()
        {
            var listOfImports = new StringBuilder();

            if (null != ImportNamespace.ListOfNamessapces)
                foreach (var item in ImportNamespace.ListOfNamessapces)
                    listOfImports.Append(IMPORTS
                        .ReplaceProperty(item)
                        .ReplaceNewLine());

            return NAMESPACE
                .ReplaceClass(_nameSpace)
                .ReplacePropertyType(listOfImports.ToString())
                .ReplaceConstructorContent(_content)
                .ReplaceComment(COMMENT1, 1)
                .ReplaceNewLine();

        }

        #endregion
    }
}
